<template>
	<view class="feedback">
		<view class="header">此投诉为本小程序自有投诉渠道，非微信官方投诉道</view>
		<scroll-view scroll-y="true" class="scroll_y">
			<view class="coms_y">
				<view class="comlum_box">
					<StepInput :title="'您的姓名'" class="mb">
						<u-input type="text" v-model="query.title" :border="false" input-align="right" placeholder="请填写您的姓名" :clearable="false"/>
					</StepInput>
					<StepInput :title="'手机号码'" class="mb">
						<u-input type="number" maxlength="11" v-model="query.mobile" :border="false" input-align="right" placeholder="请填写手机号码" :clearable="false"/>
					</StepInput>
					<view class="comlum_Y mb">
						<view class="left">
							<view class="star">
								*
							</view>
							<view class="size">
								反馈意见
							</view>
						</view>
						<u-input type="textarea" v-model="query.content" :border="false" :height="230" :auto-height="false"
							:custom-style="customStyle" placeholder="请填写您的反馈意见" :clearable="false"/>
					</view>

					<view class="comlum_Y">
						<view class="left">
							<view class="size">
								反馈图片(选填，最多9张)
							</view>
						</view>
						<view class="photo">
							<image :src="$IMG_URL('/static/user/upload.png')" mode="" class="upload" v-if="query.image_list.length < 9" @tap.stop="addImage"></image>
							<view v-for="(item,index) in query.image_list" :key="index" class="Item">
								<image :src="item" mode="" class="img"></image>
								<image :src="$IMG_URL('/static/user/close.png')" mode="" class="close" @click="close(index)">
								</image>
							</view>
							
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="foot">
			<view class="btn" @click="feedback">
				提交反馈
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import StepInput from './become_coach/components/StepInput.vue'
	import{
		submit
	} from '@/api/user.js'
	export default {
		components: {
			StepInput
		},
		data() {
			return {
				query:{
					title:'',
					mobile:null,
					content:'',
					image_list:[]
				},
				customStyle: {
					background: '#f6f6f6',
					padding: '32rpx'
				},
				photo: [],
			}
		},
		methods: {
			close(index){
				this.query.image_list.splice(index, 1)
			},
			addImage() {
				let that = this;
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ["original"], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ["album", "camera"], //从相册选择
					success: function(res) {
						res.tempFilePaths.forEach(i=>{
							that.$UPLOADIMAGE(i, 'feedback').then(imgUrl => {
								console.log('imgUrl', imgUrl);
								that.query.image_list.push(imgUrl)
								// that.$forceUpdate()
							})
						})
						
					},
				});
			},
			feedback() {
				submit(this.query).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						this.$refs.uToast.show({
							title: '已提交成功，感谢您的反馈',
							type: 'success',
							icon: false,
							back:true
						})
					}else{
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
							icon: false,
						})
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #E9E9E9;
	}

	.mb {
		margin-bottom: 48rpx;
	}
	.header{
		width: 100%;
		background: #73F0EA;
		padding: 10rpx 0;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: 500;
		text-align: left;
		color: #ffffff;
		display: flex;
		justify-content: center;
		
	}

	.feedback {

		display: flex;
		flex-direction: column;
		align-items: center;

	}

	.scroll_y {
		height: 89vh;
		width: 100%;
	}

	.coms_y {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.comlum_box {
		margin-top: 24rpx;
		width: 702rpx;
		background: #ffffff;
		border-radius: 16rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx;
	}

	.comlum_Y {
		display: flex;
		flex-direction: column;
		width: 622rpx;

	}

	.left {
		display: flex;
		flex-direction: row;
		flex: 1;
		margin-bottom: 24rpx;

		.star {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #f37364;
		}

		.size {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #333333;
		}
	}

	.upload_img {
		width: 204rpx;
		height: 204rpx;
	}

	.photo {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		flex-wrap: wrap;
		width: 100%;
	}

	.upload {
		width: calc((100% - 24rpx) / 3);
		height: 204rpx;
		margin-right: 12rpx;
		/* 右边距 */
		margin-bottom: 12rpx;
	}

	.upload:last-child {
		margin-right: 0;
		/* 如果是最后一个元素，移除右边距 */
	}

	.Item:nth-child(3n) {
		margin-right: 0;
		/* 每行的第三个元素没有右边距 */
	}

	.Item {
		width: calc((100% - 24rpx) / 3);
		/* 每行三个元素，包括间距 */
		height: 204rpx;
		background: rgba(0, 0, 0, 0.00);
		border-radius: 16rpx;
		overflow: hidden;
		position: relative;
		margin-right: 12rpx;
		/* 右边距 */
		margin-bottom: 12rpx;

		.close {
			position: absolute;
			right: 0;
			top: 0;
			width: 52rpx;
			height: 52rpx;
		}

		.img {
			width: 100%;
			height: 100%;
		}
	}

	.foot {
		position: fixed;
		bottom: 0;
		width: 750rpx;
		height: 160rpx;
		background: #ffffff;
		box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(166, 179, 194, 0.30);
		display: flex;
		justify-content: center;
		padding-top: 10rpx;

		.btn {
			width: 710rpx;
			height: 88rpx;
			background: #73F0EA;
			border-radius: 16rpx;
			font-size: 34rpx;
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			color: #ffffff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>